package com.wangyonghui.service.user.controller;

import com.wangyonghui.service.user.config.ResultEntity;
import com.wangyonghui.service.user.entity.User;
import com.wangyonghui.service.user.service.UserService;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
//Vue是district里的USer
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;
    @RequestMapping("/list")
    public ResultEntity list(@RequestParam(defaultValue = "1")Integer pageNum, @RequestParam(defaultValue = "3")Integer pageSize, User user){
        Page<User> pageInfo = userService.list(pageNum, pageSize, user);
        System.err.print("User的展示数据"+pageInfo);
        return ResultEntity.ok(pageInfo);
    }

    //添加
    @RequestMapping("/save")
    public ResultEntity save(@RequestBody User user){
//        Md5Util.convertMD5()
        System.err.print("添加接收到的数据"+user);
        return ResultEntity.ok(userService.save(user));
    }

    @RequestMapping("update")
    public ResultEntity update(@RequestBody User user){
        return ResultEntity.ok(userService.save(user));
    }

    @RequestMapping("/delete")
    public ResultEntity delete(Integer[] ids){
        try {
            userService.delete(ids);
            return ResultEntity.ok(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultEntity.error(false);
    }

}
